package cn.com.lyj6851.modules.shop.service.impl;

import cn.com.lyj6851.common.service.impl.BaseServiceImpl;
import cn.com.lyj6851.common.utils.QueryHelpPlus;
import cn.com.lyj6851.dozer.service.IGenerator;
import cn.com.lyj6851.modules.shop.domain.YdyMaterial;
import cn.com.lyj6851.modules.shop.service.YdyMaterialService;
import cn.com.lyj6851.modules.shop.service.dto.YdyMaterialDto;
import cn.com.lyj6851.modules.shop.service.dto.YdyMaterialQueryCriteria;
import cn.com.lyj6851.modules.shop.service.mapper.MaterialMapper;
import com.github.pagehelper.PageInfo;
import lombok.AllArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

@Service
@AllArgsConstructor
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class YdyMaterialServiceImpl extends BaseServiceImpl<MaterialMapper, YdyMaterial> implements YdyMaterialService {

    private final IGenerator generator;

    @Override
    //@Cacheable
    public Map<String, Object> queryAll(YdyMaterialQueryCriteria criteria, Pageable pageable) {
        getPage(pageable);
        PageInfo<YdyMaterial> page = new PageInfo<>(queryAll(criteria));
        Map<String, Object> map = new LinkedHashMap<>(2);
        map.put("content", generator.convert(page.getList(), YdyMaterialDto.class));
        map.put("totalElements", page.getTotal());
        return map;
    }


    @Override
    //@Cacheable
    public List<YdyMaterial> queryAll(YdyMaterialQueryCriteria criteria){
        return baseMapper.selectList(QueryHelpPlus.getPredicate(YdyMaterial.class, criteria));
    }



}
